home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / SHOWFILE / SHOW.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  41.3 KB  |  1,979 lines

  1. /* showf.c */
  2.  
  3.  
  4. #include "obdefs.h"
  5. #include "gemdefs.h"
  6. #include "osbind.h"
  7. #include "mydefs.h"
  8. #include "show.h"
  9. #include "addr.h"
  10. #include "error.h"
  11. #include "errno.h"
  12. #include "stat.h"
  13.  
  14.  
  15. #define MAX(X,Y)    ( (X) > (Y) ? (X) : (Y) )
  16. #define MIN(X,Y)    ( (X) < (Y) ? (X) : (Y) )
  17. #define NARGV 128
  18.  
  19.  
  20. /* AES (windows and messages) related variables */
  21. int gl_hchar;        /* height of system font (pixels) */
  22. int gl_wchar;        /* width of system font (pixels) */
  23. int gl_wbox;        /* width of box able to hold system font */
  24. int gl_hbox;        /* height of box able to hold system font */
  25.  
  26. extern int gl_apid;
  27.  
  28. int phys_handle;    /* physical workstation handle */
  29. int handle;            /* virtual workstation handle */
  30. int wi_handle;        /* window handle */
  31.  
  32. int formw, formh, sx, sy, lx, ly;    /* dialogue box dimensions */
  33. int xdesk, ydesk, hdesk, wdesk;        /* window X, Y, width, height */
  34. int xwork, ywork, hwork, wwork;        /* desktop and work areas */
  35.  
  36. char *sbuf[512];
  37. int keycode;        /* keycode returned by event-keyboard */
  38. int mx, my;        /* mouse x and y pos. */
  39. int butdown;        /* button state tested for, UP/DOWN */
  40. int ret;        /* dummy return variable */
  41. int hidden;        /* current state of cursor */
  42. int contrl[12];
  43. int intin[128];
  44. int ptsin[128];
  45. int intout[128];
  46. int ptsout[128];    /* storage wasted for idiotic bindings */
  47. int work_in[11];    /* Input to GSX parameter array */
  48. int work_out[57];    /* Output from GSX parameter array */
  49. int pxyarray[10];    /* input point array */
  50. int msg[8];            /* message buffer */
  51. long toptx;            /* the top line of text currently in the window */
  52. long leftx;            /* the most left text in the window */
  53. char *dbuff;        //* a format buffer of a file */
  54. char *sbuff;        //* a source buffer of a file */
  55. long *list;            /* the list of pointer of lines in a file */
  56. long nrow;            /* total number of lines in a file */
  57. int running;
  58. long maxln=0;            /* the longest of text in a file */
  59. long fsiz;            /* the size of show file */
  60. char *tolstr = "9999";
  61. char info[120];    /* buffer for the infomation in the window */
  62. char showfn[24];    /* buffer of the name of show file */
  63. int tolfile;    /* the number of files to be show */
  64. int fno=1;        /* the index of the file list */
  65. int prvfno=0;    /* the previous show file */
  66. int prvfmt;        /* the previous show file format*/
  67. int showasc=1;    /* 1: show the as ascii file */
  68. int showlen;    /* the lenth of the show file */
  69. int showstd;    /* the start pointer of the show file */
  70. int openyes;    /* 1: open a new file */
  71. DMABUFFER dma;
  72.  
  73. static char argcopy[128];
  74. static char *argv[NARGV];
  75.  
  76. main(argc, argv)
  77. int argc;
  78. char *argv[];
  79. {
  80.  
  81.  
  82.     int done = FALSE;
  83.     int skip = 0;
  84.     int rut;
  85.  
  86.     appl_init();
  87.     phys_handle=graf_handle(&gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox);
  88.     wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
  89.     rut = open_vwork();
  90.  
  91.     if (!rsrc_load(RESOURCEFILE))    {
  92.         errs("[2][|", RESOURCEFILE, "][ EXIT ]");
  93.         goto doneit;
  94.     }
  95.     
  96.     /* Get all addresses of dialogues from resource file */
  97.     if (getalladdr() != OK) {
  98.         errs("[2][|", RESOURCEFILE, "][ EXIT ]");
  99.         goto doneit;
  100.     }
  101.  
  102.     ARROW_MOUSE;
  103.     if (!rut)    {    /* can't open the virtual workstation */
  104.         form_alert(1, cnopen);
  105.         goto donothing;
  106.     }
  107.     getargs(&argc, &argv);
  108.     if (argc > 1)    {
  109.         tolfile = argc-1;
  110.     resel:
  111.         if (select(skip) == EXIT)    {
  112.             goto donothing;
  113.         } else {    /* 1: first time to open the window */
  114.             running = TRUE;
  115.             openyes = 1;
  116.             if ((rut=doopenwd(1, argv[fno])) == OK)    {
  117.                 skip = 1;
  118.                 goto resel;
  119.             } else if (rut == ERROR)    {
  120.                 running = 0;
  121.                 goto donothing;
  122.             }    /* else keep go on */
  123.         }
  124.         while(running)    {
  125.             domulti();
  126.         }
  127.     } else {
  128.         form_alert(1, needfile);
  129.         goto donothing;
  130.     }
  131.  
  132.     vst_alignment(handle, 0, 0, &done, &done); /*set text alignment*/
  133.  
  134. doneit:
  135.     wind_delete(wi_handle);
  136.     Mfree(dbuff);
  137.     Mfree(sbuff);
  138.     Mfree(list);
  139. donothing:
  140.     v_clsvwk(handle);
  141.     appl_exit();
  142. }
  143.  
  144. /* do the open window, read the files, and format them, then show them */
  145.  
  146. doopenwd(first, path)
  147. int first;
  148. char *path;
  149. {
  150.  
  151.     int done = FALSE;
  152.     long slidsiz, dsize;
  153.     int hsldsiz;
  154.     int i, tmpy, tmpx, fp;
  155.     char *tem;
  156.     long *tmp;
  157.     char *s1 =" bytes used in 1 item.     NOTE: Hit 'Help' key for selection.";
  158.     int showbin=0;
  159.     long findrow(), ckupper(), gdbufsiz();
  160.     /*
  161.     int minADE, maxADE, maxwidth;
  162.     int distances[5], effects[3];
  163.     */
  164.     int attrib[10];
  165.  
  166.  
  167.     BEE_MOUSE;
  168.     if (fno == prvfno) {
  169.         if ((prvfmt) && (!showasc))    {/* prevous and now showing binary fmt */
  170.             goto skpconv;
  171.         } else if ((!prvfmt) && (showasc))    {/* prv & now showing ascii fmt */
  172.             goto skpconv;
  173.         } else {
  174.             Mfree(dbuff);
  175.             Mfree(list);
  176.             fsiz = dma.d_fsize;
  177.             goto skprd;
  178.         } 
  179.     } 
  180.     if (!first)    {
  181.         Mfree(dbuff);
  182.         Mfree(sbuff);
  183.         Mfree(list);
  184.     }
  185.     Fsetdta(&dma);
  186.     if (Fsfirst(path, 0x3F) != 0)    {
  187.         ARROW_MOUSE;
  188.         if (form_alert(2, cnfdf) == 1)    {
  189.             return OK;        /* skip */
  190.         } else {            /* cancel */
  191.             erasemsg();        /* erase the select dialog box */
  192.             return ERROR;
  193.         }
  194.     }
  195.     info[0] = 0x20;
  196.     fsiz = dma.d_fsize;
  197.     itoa(dma.d_fsize, &info[1]);
  198.     strcat(&info[0], s1);
  199.  
  200.     /* read the file into buffer */
  201.  
  202.     if ((sbuff = Malloc(dma.d_fsize + 150)) == NULL)    {
  203.         ARROW_MOUSE;
  204.         if (form_alert(2, outmem) == 1)    {
  205.             return OK;        /* skip */
  206.         } else {            /* cancel */
  207.             erasemsg();        /* erase the select dialog box */
  208.             return ERROR;
  209.         }
  210.     }
  211.     if ((fp = Fopen(path, 0)) < 0)    {
  212.         ARROW_MOUSE;
  213.         Mfree(sbuff);
  214.         if (form_alert(2, cnopf) == 1)    {
  215.             return OK;        /* skip */
  216.         } else {            /* cancel */
  217.             erasemsg();        /* erase the select dialog box */
  218.             return ERROR;
  219.         }
  220.     }
  221.     if (Fread(fp, dma.d_fsize, sbuff) < 0)    {
  222.         ARROW_MOUSE;
  223.         Mfree(sbuff);
  224.         Fclose(fp);            /* close the previous file */
  225.         if (form_alert(2, cnrdf) == 1)    {
  226.             return OK;        /* skip */
  227.         } else {            /* cancel */
  228.             erasemsg();        /* erase the select dialog box */
  229.             return ERROR;
  230.         }
  231.     }
  232.     Fclose(fp);            /* close the previous file */
  233.  
  234. skprd:
  235.     if ((showbin=binary(sbuff)) || (!showasc))    {
  236.         /*it is a binary file or show as binary*/
  237.         if ((showbin) && (showasc))    {
  238.             ARROW_MOUSE;
  239.             form_alert(1, binonly);
  240.             BEE_MOUSE;
  241.         } else {
  242.             showbin = 1;
  243.         }
  244.         /* every 16 bytes of sbuf needs 67 bytes of dbuf */
  245.         dsize = (dma.d_fsize/16+2)*67;         
  246.     } else {
  247.         dsize = gdbufsiz(sbuff, dma.d_fsize) + 1000;
  248.     }
  249.     if ((dbuff = Malloc(dsize)) == NULL)    {
  250.         ARROW_MOUSE;
  251.         Mfree(sbuff);
  252.         if (form_alert(2, outmem) == 1)    {
  253.             return OK;        /* skip */
  254.         } else {            /* cancel */
  255.             erasemsg();        /* erase the select dialog box */
  256.             return ERROR;
  257.         }
  258.     }
  259.     /* find out it is a binary file or not */
  260.     if (showbin)    {        /*it is a binary file or show as binary*/
  261.         nrow = dma.d_fsize/16;
  262.         if (dma.d_fsize%16)    {
  263.             nrow += 1;
  264.         }
  265.         if ((list = Malloc(nrow*4)) == NULL)    {
  266.             if (nrow)    {
  267.                 Mfree(sbuff);
  268.                 Mfree(dbuff);
  269.                 ARROW_MOUSE;
  270.                 if (form_alert(2, outmem) == 1)    {
  271.                     return OK;        /* skip */
  272.                 } else {            /* cancel */
  273.                     erasemsg();        /* erase the select dialog box */
  274.                     return ERROR;
  275.                 }
  276.             }
  277.         }
  278.         bin2str(list, sbuff, dbuff);
  279.     } else     {             /* it is a asci file */
  280.         nrow = findrow(sbuff, dma.d_fsize);
  281.         if ((list = Malloc(nrow*4)) == NULL)    {
  282.             if (nrow)    {
  283.                 ARROW_MOUSE;
  284.                 Mfree(dbuff);
  285.                 Mfree(sbuff);
  286.                 if (form_alert(2, outmem) == 1)    {
  287.                     return OK;        /* skip */
  288.                 } else {            /* cancel */
  289.                     erasemsg();        /* erase the select dialog box */
  290.                     return ERROR;
  291.                 }
  292.             }
  293.         }
  294.         asci2str(list, sbuff, dbuff, dma.d_fsize);
  295.  
  296.     }
  297.     /*
  298.      * Draw shrinking box and cleanup the screen;
  299.      * return thing that caused our exit.
  300.      */
  301.  
  302. skpconv:
  303.     erasemsg();        /* erase the select dialog box */
  304.  
  305.     if (first)    {    /* it is the first time to open the window */
  306.         wi_handle=wind_create(0x0FFF, xdesk, ydesk, wdesk, hdesk);
  307.     }
  308.     wind_set(wi_handle, WF_INFO, &info[0], 0, 0);
  309.     wind_set(wi_handle, WF_NAME, ckupper(path), 0, 0);
  310.     if (first)    {
  311.         wind_open(wi_handle, xdesk+30, ydesk+40, gl_wchar*70, gl_hchar*13);
  312.         vst_alignment(handle, 0, 5, &done, &done); 
  313.     }
  314.     /*
  315.     vqt_fontinfo(phys_handle, &minADE, &maxADE, distances, &maxwidth, effects);
  316.     */
  317.     vqt_attributes(phys_handle, attrib);
  318.     vst_height(handle, attrib[7], &done, &done, &done, &done);
  319.        wind_get(wi_handle, WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork);
  320.  
  321.     toptx = 0;        /* start top line of text */
  322.     leftx = 0;         /* left side of the text */
  323.  
  324.     /* find slider size and set it */
  325.     if (!nrow)    {
  326.         slidsiz = 1000;
  327.     } else {
  328.         slidsiz = (1000*hwork/gl_hchar) / nrow; 
  329.     }
  330.     if (!maxln)    {
  331.         hsldsiz = 1000;
  332.     } else {
  333.         hsldsiz = (1000*wwork/gl_wchar) / maxln;
  334.     }
  335.     wind_set(wi_handle, WF_VSLSIZE, (int)slidsiz, 0, 0, 0);
  336.     wind_set(wi_handle, WF_HSLSIZE, hsldsiz, 0, 0, 0);
  337.     mvslide(wi_handle, 3, 1);
  338.     mvslide(wi_handle, 4, 1);
  339.     ARROW_MOUSE;
  340.     redwmsg(wi_handle); 
  341.     prvfno = fno;
  342.     prvfmt = showbin;
  343.     return YES;
  344. }
  345.  
  346.  
  347.  
  348. /* send don't redraw message to the window */
  349.  
  350. redwmsg(wh)
  351.  
  352. int wh;
  353.  
  354. {
  355.     int msg[8];
  356.  
  357.     msg[0] = WM_REDRAW;
  358.     msg[1] = gl_apid;
  359.     msg[2] = 0;
  360.     msg[3] = wh;
  361.     msg[4] = 0;
  362.     msg[5] = 0;
  363.     msg[6] = 0;
  364.     msg[7] = 0;
  365.     appl_write(gl_apid, 16, &msg);
  366. }
  367.  
  368.  
  369. /* check the path name is a directory or not, if is, return 1 */
  370.  
  371. isdir(path)
  372.  
  373. char *path;
  374.  
  375. {
  376.  
  377.     char *ptr;
  378.     int dir=0;
  379.  
  380.     ptr = path;
  381.     while(*ptr)    {
  382.         ptr++;
  383.     }
  384.     if (*(ptr-1) == 0x5C)    {    /* if it is a backslash, it is a directory */
  385.         dir = 1;
  386.     } 
  387.     return(dir);
  388. }
  389.  
  390.  
  391. long ckupper(ptr)
  392. char *ptr;
  393. {
  394.     char *stmp, *dtmp;
  395.  
  396.     stmp = ptr;
  397.     dtmp = ptr;
  398.     while (*stmp)    {
  399.         *dtmp++ = (char)toupper((int)*stmp++);
  400.     }
  401.     return ptr;
  402. }
  403.  
  404. itoa(n, s)
  405. long n;
  406. char s[];
  407.  
  408. {
  409.     int i;
  410.     long sign;
  411.  
  412.     if ((sign = n) < 0) /* record sign */
  413.         n = -n;            /* make n positive */
  414.     i = 0;
  415.     do     {
  416.         s[i++] = n % 10 + '0';
  417.     } while ((n /= 10) > 0);
  418.     if (sign < 0)
  419.         s[i++] = '-';
  420.     s[i] = '\0';
  421.     reverse(s);
  422. }
  423.  
  424. reverse(s)
  425. char s[];
  426. {
  427.     int c, i, j;
  428.  
  429.     for (i = 0, j=strlen(s)-1; i < j; i++, j--)     {
  430.         c = s[i];
  431.         s[i] = s[j];
  432.         s[j] = c;
  433.     }
  434. }
  435.  
  436. /* this function do the WM_FULLED message */
  437.  
  438. toggle(wh)        
  439. int wh;
  440. {
  441.  
  442.     GRECT prv, cur, full;
  443.  
  444.     /* get the previous, current, and the full size of windows */
  445.     wind_get(wh, WF_PREVXYWH, &prv.g_x, &prv.g_y, &prv.g_w, &prv.g_h);
  446.     wind_get(wh, WF_CURRXYWH, &cur.g_x, &cur.g_y, &cur.g_w, &cur.g_h);
  447.     wind_get(wh, WF_FULLXYWH, &full.g_x, &full.g_y, &full.g_w, &full.g_h);
  448.  
  449.     /* if it is full size, change it to previous unless that was full also */
  450.  
  451.     if (((cur.g_x == full.g_x) &&
  452.          (cur.g_y == full.g_y) &&
  453.          (cur.g_w == full.g_w) &&
  454.          (cur.g_h == full.g_h)) &&
  455.              ((prv.g_x != full.g_x) ||
  456.               (prv.g_y != full.g_y) ||
  457.               (prv.g_w != full.g_w) ||
  458.               (prv.g_h != full.g_h)))     {
  459.         wind_set(wh, WF_CURRXYWH, prv.g_x, prv.g_y, prv.g_w, prv.g_h);
  460.         wind_get(wh, WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork);
  461.         prv.g_x = xwork;
  462.         prv.g_y = ywork;
  463.         prv.g_h = hwork;
  464.         prv.g_w = wwork;
  465.     } else {
  466.         wind_set(wh, WF_CURRXYWH, full.g_x, full.g_y, full.g_w, full.g_h);
  467.         wind_get(wh, WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork);
  468.         if (maxln <= wwork/gl_wchar)    {
  469.             leftx = 0;
  470.         }
  471.         if (nrow <= hwork/gl_hchar)    {
  472.             toptx = 0;
  473.         }
  474.     }
  475.     mvslide(wh, 4, 1);
  476.     mvslide(wh, 3, 1);
  477. }
  478.  
  479.  
  480. Redraw(msg, dbox)    
  481.  
  482. int msg;        /* window handle from msg[3] */
  483. GRECT *dbox;    /* pointer to the redraw rectangle */
  484.  
  485. {  
  486.  
  487.     GRECT wdrct;    /* the current window rectangle in rect list */ 
  488.     int done;
  489.     int temp[4];
  490.  
  491.     hide_mouse();        /* turn off mouse */
  492.     wind_update(BEG_UPDATE);    /* lock screen */
  493.     vsf_interior(handle, 1);    
  494.     vsf_color(handle, 0);
  495.     wind_get
  496.         (msg, WF_FIRSTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  497.     while (wdrct.g_w && wdrct.g_h)    {    /* while it is not the last one */
  498.         if (rc_intersect(dbox, &wdrct))    { /*check see if this one is damaged*/ 
  499.             setclip(&wdrct);
  500.             temp[0] = wdrct.g_x;
  501.             temp[1] = wdrct.g_y;
  502.             temp[2] = wdrct.g_x + wdrct.g_w - 1;
  503.             temp[3] = wdrct.g_y + wdrct.g_h - 1;
  504.             v_bar(handle, temp);
  505.             writewd(msg);                /* redraw the window */
  506.         }
  507.         wind_get
  508.           (msg, WF_NEXTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  509.     }
  510.     wind_update(END_UPDATE);    /* unlock screen */
  511.     show_mouse();        /* turn on mouse */
  512.  
  513. }
  514.  
  515.  
  516. /* draw and display the window */
  517.  
  518. writewd(msg)
  519.  
  520. int msg;
  521. {
  522.     int i, j, k;
  523.     int x, y, w, h;
  524.  
  525.     j = nrow - toptx;    /* number of line left */
  526.     wind_get(msg, WF_WORKXYWH, &x, &y, &w, &h);
  527.     k = ((h-1)%gl_hchar)?((h-1)/gl_hchar+1):((h-1)/gl_hchar);
  528.     for (i=0; i < k; i++)    {
  529.         if (toptx+i < nrow)    {
  530.             v_gtext(handle, x-(int)leftx*gl_wchar, 
  531.                             gl_hchar*i + y, *(list+toptx+i));
  532.         } else    {
  533.             break;
  534.         }
  535.     }
  536. }
  537.  
  538.  
  539. blit2lf(msg, dbox)    
  540.  
  541. int msg;        /* window handle from msg[3] */
  542. GRECT *dbox;    /* pointer to the redraw rectangle */
  543.  
  544. {  
  545.  
  546.     GRECT wdrct;    /* the current window rectangle in rect list */ 
  547.     int done;
  548.  
  549.     /*
  550.     hide_mouse();        
  551.     */
  552.     wind_update(BEG_UPDATE);    /* lock screen */
  553.     vsf_interior(handle, 1);    
  554.     vsf_color(handle, 0);
  555.     wind_get
  556.         (msg, WF_FIRSTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  557.     while (wdrct.g_w && wdrct.g_h)    {    /* while it is not the last one */
  558.         if (rc_intersect(dbox, &wdrct))    { /*check see if this one is damaged*/ 
  559.             setclip(&wdrct);
  560.             blitlf(msg, &wdrct);
  561.         }
  562.         wind_get
  563.           (msg, WF_NEXTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  564.     }
  565.     wind_update(END_UPDATE);    /* unlock screen */
  566.     /*
  567.     show_mouse();
  568.     */
  569.  
  570. }
  571.  
  572.  
  573. /* redraw the window */
  574.  
  575. blitlf(wh, box)
  576. int wh;
  577. GRECT *box;
  578.  
  579. {
  580.     int i, j, k, l, m, done;
  581.     GRECT rect;
  582.     int pxyarray[8];
  583.     int x[2]; 
  584.     char *pt;
  585.     char y[3];
  586.  
  587.     x[0] = 0;
  588.     x[1] = 0;
  589.     y[1] = 0;
  590.     y[2] = 0;
  591.  
  592.     graf_mouse(M_OFF, 0L);
  593.     pxyarray[0] = box->g_x;
  594.     pxyarray[1] = box->g_y;
  595.     pxyarray[2] = box->g_x+box->g_w-gl_wchar;
  596.     pxyarray[3] = box->g_y+box->g_h;
  597.     pxyarray[4] = box->g_x+gl_wchar;
  598.     pxyarray[5] = box->g_y;
  599.     pxyarray[6] = box->g_x+box->g_w;
  600.     pxyarray[7] = box->g_y+box->g_h;
  601.     vro_cpyfm(handle, 3, pxyarray, &x[0], &x[0]);
  602.     rect.g_x = box->g_x;
  603.     rect.g_y = box->g_y;
  604.     rect.g_w = gl_wchar;
  605.     rect.g_h = box->g_h;
  606.     clrbox(&rect);            /* clear this line */
  607.     j = nrow - toptx;    /* number of line left */
  608.     i = box->g_y-ywork+box->g_h-1;
  609.     k = (i%gl_hchar)?(i/gl_hchar+1):(i/gl_hchar);
  610.     i = (box->g_y-ywork)/gl_hchar;
  611.     for (; i < k; i++)    {
  612.         if (j > i)    {
  613.             pt = *(list+toptx+i);
  614.             if (box->g_x == xwork)    {
  615.                 l = lenth(pt);
  616.                 if ((*pt == 0x20) && (l < 2))    {
  617.                     ;                /* do nothing */
  618.                 } else if (l > leftx)    {
  619.                     pt = pt + leftx;
  620.                     y[0] = *pt;
  621.                     v_gtext(handle, xwork, gl_hchar*i+ ywork, &y[0]);
  622.                 }
  623.             } else {
  624.                 l = lenth(pt);
  625.                 m = (box->g_x-xwork)/gl_wchar;
  626.                 if ((l-leftx) >= m)    {
  627.                     pt = pt + leftx + m;
  628.                     y[0] = *pt;
  629.                     if (((box->g_x-xwork)%gl_wchar))    {
  630.                         y[1] = *(pt+1);
  631.                     }
  632.                     v_gtext(handle,  xwork+m*gl_wchar, 
  633.                                             gl_hchar*i+ywork, &y[0]);
  634.                 }
  635.             }
  636.         } else    {
  637.             break;
  638.         }
  639.     }
  640.     graf_mouse(M_ON, 0L);
  641. }
  642.  
  643. blit2rt(msg, dbox)    
  644.  
  645. int msg;        /* window handle from msg[3] */
  646. GRECT *dbox;    /* pointer to the redraw rectangle */
  647.  
  648. {  
  649.  
  650.     GRECT wdrct;    /* the current window rectangle in rect list */ 
  651.     int done;
  652.  
  653.     /*
  654.     hide_mouse();    
  655.     */
  656.     wind_update(BEG_UPDATE);    /* lock screen */
  657.     vsf_interior(handle, 1);    
  658.     vsf_color(handle, 0);
  659.     wind_get
  660.         (msg, WF_FIRSTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  661.     while (wdrct.g_w && wdrct.g_h)    {    /* while it is not the last one */
  662.         if (rc_intersect(dbox, &wdrct))    { /*check see if this one is damaged*/ 
  663.             setclip(&wdrct);
  664.             blitrt(msg, &wdrct);
  665.         }
  666.         wind_get
  667.           (msg, WF_NEXTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  668.     }
  669.     wind_update(END_UPDATE);    /* unlock screen */
  670.     /*
  671.     show_mouse();
  672.     */
  673. }
  674.  
  675.  
  676. blitrt(wh, box)
  677. int wh;
  678. GRECT *box;
  679.  
  680. {
  681.     int i, j, k, l, done;
  682.     GRECT rect;
  683.     int pxyarray[8];
  684.     int x[2]; 
  685.     char y[3];
  686.     char *pt;
  687.  
  688.     x[0] = 0;
  689.     x[1] = 0;
  690.     y[1] = 0;
  691.     y[2] = 0;
  692.  
  693.     graf_mouse(M_OFF, 0L);
  694.     pxyarray[0] = box->g_x+gl_wchar;
  695.     pxyarray[1] = box->g_y;
  696.     k = ((box->g_x-xwork+box->g_w-1)/gl_wchar)*gl_wchar;
  697.     pxyarray[2] = xwork+k;
  698.     pxyarray[3] = box->g_y+box->g_h;
  699.     pxyarray[4] = box->g_x;
  700.     pxyarray[5] = box->g_y;
  701.     pxyarray[6] = pxyarray[2]-gl_wchar;
  702.     pxyarray[7] = box->g_y+box->g_h;
  703.     vro_cpyfm(handle, 3, pxyarray, &x[0], &x[0]);
  704.     rect.g_x = xwork+ k - gl_wchar;
  705.     rect.g_y = box->g_y;
  706.     rect.g_w = ((box->g_x-xwork+box->g_w-1)%gl_wchar)?
  707.                 (box->g_x-xwork+box->g_w-k+gl_wchar) : (gl_wchar+1);
  708.     rect.g_h = box->g_h;
  709.     clrbox(&rect);             
  710.     j = nrow - toptx;    /* number of line left */
  711.     i = box->g_y-ywork+box->g_h-1;
  712.     l = (i%gl_hchar)?(i/gl_hchar+1):(i/gl_hchar);
  713.     i = (box->g_y-ywork)/gl_hchar;
  714.     for (; i < l; i++)    {
  715.         if (j > i)    {
  716.             pt = *(list+toptx+i);
  717.             if (((lenth(pt)-leftx+1)*gl_wchar) >= box->g_x-xwork+box->g_w)     {
  718.                 pt = pt + k/gl_wchar+leftx-1;
  719.                 y[0] = *pt;
  720.                 if (*pt) {
  721.                     y[1] = *(pt+1);
  722.                 }
  723.                 v_gtext(handle, xwork+k-gl_wchar, gl_hchar*i+ywork, &y[0]);
  724.             }
  725.         } else    {
  726.             break;
  727.         }
  728.     }
  729.     graf_mouse(M_ON, 0L);
  730. }
  731.  
  732.  
  733. lenth(pt)
  734. char *pt;
  735. {
  736.     int i=0;
  737.  
  738.     while (*pt++)    {
  739.         i++;
  740.     }
  741.     return i;
  742. }
  743.  
  744. blitup(wh, box)
  745. int wh;
  746. GRECT *box;
  747.  
  748. {
  749.     int i, j, done;
  750.     GRECT rect;
  751.     int pxyarray[8];
  752.     int x[2];
  753.  
  754.     x[0] = 0;
  755.     x[1] = 0;
  756.  
  757.     i = ((box->g_y-ywork+hwork-1)/gl_hchar)*gl_hchar;
  758.  
  759.     graf_mouse(M_OFF, 0L);
  760.     pxyarray[0] = box->g_x;
  761.     pxyarray[1] = box->g_y;
  762.     pxyarray[2] = box->g_x+box->g_w;
  763.     pxyarray[3] = ywork+i;
  764.     pxyarray[4] = box->g_x;
  765.     pxyarray[5] = box->g_y+gl_hchar;
  766.     pxyarray[6] = box->g_x+box->g_w;
  767.     pxyarray[7] = pxyarray[3]+gl_hchar;
  768.     vro_cpyfm(handle, 3, pxyarray, &x[0], &x[0]);
  769.     rect.g_x = box->g_x;
  770.     rect.g_y = box->g_y;
  771.     rect.g_w = box->g_w;
  772.     rect.g_h = gl_hchar;
  773.     clrbox(&rect);            /* clear this line */
  774.     i = (box->g_y-ywork)/gl_hchar;
  775.     j = (box->g_y-ywork)%gl_hchar;
  776.     if (toptx+i < nrow)    {
  777.         v_gtext(handle, xwork-(int)leftx*gl_wchar, i*gl_hchar+ywork, 
  778.                             *(list+toptx+i));
  779.     }
  780.     if ((j)&&(toptx+i+1 < nrow))    {
  781.         v_gtext(handle, xwork-(int)leftx*gl_wchar, (i+1)*gl_hchar+ywork, 
  782.                             *(list+toptx+i+1));
  783.     }
  784.     graf_mouse(M_ON, 0L);
  785. }
  786.  
  787. blit2up(msg, dbox)    
  788.  
  789. int msg;        /* window handle from msg[3] */
  790. GRECT *dbox;    /* pointer to the redraw rectangle */
  791.  
  792. {  
  793.  
  794.     GRECT wdrct;    /* the current window rectangle in rect list */ 
  795.     int done;
  796.     /*
  797.     hide_mouse();    
  798.     */
  799.     wind_update(BEG_UPDATE);    /* lock screen */
  800.     vsf_interior(handle, 1);    
  801.     vsf_color(handle, 0);
  802.     wind_get
  803.         (msg, WF_FIRSTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  804.     while (wdrct.g_w && wdrct.g_h)    {    /* while it is not the last one */
  805.         if (rc_intersect(dbox, &wdrct))    { /*check see if this one is damaged*/ 
  806.             setclip(&wdrct);
  807.             blitup(msg, &wdrct);
  808.         }
  809.         wind_get
  810.           (msg, WF_NEXTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  811.     }
  812.     wind_update(END_UPDATE);    /* unlock screen */
  813.     /*
  814.     show_mouse();
  815.     */
  816.  
  817. }
  818.  
  819.  
  820. blit2dn(msg, dbox)    
  821.  
  822. int msg;        /* window handle from msg[3] */
  823. GRECT *dbox;    /* pointer to the redraw rectangle */
  824.  
  825. {  
  826.  
  827.     GRECT wdrct;    /* the current window rectangle in rect list */ 
  828.     int done;
  829.     /*
  830.     hide_mouse();
  831.     */
  832.     wind_update(BEG_UPDATE);    /* lock screen */
  833.     vsf_interior(handle, 1);    
  834.     vsf_color(handle, 0);
  835.     wind_get
  836.         (msg, WF_FIRSTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  837.     while (wdrct.g_w && wdrct.g_h)    {    /* while it is not the last one */
  838.         if (rc_intersect(dbox, &wdrct))    { /*check see if this one is damaged*/ 
  839.             setclip(&wdrct);
  840.             blitdn(msg, &wdrct);
  841.         }
  842.         wind_get
  843.           (msg, WF_NEXTXYWH, &wdrct.g_x, &wdrct.g_y, &wdrct.g_w, &wdrct.g_h);
  844.     }
  845.     wind_update(END_UPDATE);    /* unlock screen */
  846.     /*
  847.     show_mouse();
  848.     */
  849.  
  850. }
  851.  
  852.  
  853. /* redraw the window */
  854. blitdn(wh, box)
  855. int wh;
  856. GRECT *box;
  857.  
  858. {
  859.     int i, j, done;
  860.     GRECT rect;
  861.     int pxyarray[8];
  862.     int x[2];
  863.  
  864.  
  865.     x[0] = 0;
  866.     x[1] = 0;
  867.     graf_mouse(M_OFF, 0L);
  868.     i = ((box->g_y-ywork+box->g_h-1)/gl_hchar)*gl_hchar;
  869.     pxyarray[0] = box->g_x;
  870.     pxyarray[1] = box->g_y+gl_hchar;
  871.     pxyarray[2] = box->g_x+box->g_w;
  872.     pxyarray[3] = ywork+i;
  873.     pxyarray[4] = box->g_x;
  874.     pxyarray[5] = box->g_y;
  875.     pxyarray[6] = box->g_x+box->g_w;
  876.     pxyarray[7] = pxyarray[3]-gl_hchar;
  877.     vro_cpyfm(handle, 3, pxyarray, &x[0], &x[0]);
  878.     j = (box->g_y-ywork+box->g_h-1)%gl_hchar;
  879.     rect.g_x = box->g_x;
  880.     rect.g_y = ywork+i-gl_hchar;
  881.     rect.g_w = box->g_w;
  882.     rect.g_h = (j)?(gl_hchar+box->g_y-ywork+box->g_h-i):(gl_hchar+1);
  883.     clrbox(&rect);            /* clear this line */
  884.     i = (box->g_y-ywork+box->g_h-1)/gl_hchar-1;
  885.     if (toptx+i < nrow)    {
  886.         v_gtext(handle,xwork-(int)leftx*gl_wchar,
  887.                         i*gl_hchar+ywork, *(list+toptx+i));
  888.     }
  889.     if ((j)&&(toptx+i+1 < nrow))    {
  890.         v_gtext(handle, xwork-(int)leftx*gl_wchar, 
  891.                         (i+1)*gl_hchar+ywork, *(list+toptx+i+1));
  892.     }
  893.     graf_mouse(M_ON, 0L);
  894. }
  895.  
  896.  
  897. /* move the slider to match top text */
  898.  
  899. mvslide(wh, msg, resiz)
  900. int wh;
  901. int msg;        /* 4: do the horizontal slide; < 3, for vertical slide */
  902. int resiz;        /* if resize the window, set for 1 */
  903. {
  904.     int cslide, nslide, flag1, flag2;
  905.     long tmp1, tmp2;
  906.  
  907.     if (msg > 3)    {    /* do the horizontal move */
  908.         flag1 = WF_HSLIDE;
  909.         flag2 = WF_HSLSIZE;
  910.         if (maxln <= wwork/gl_wchar)    {
  911.             tmp1 = 1000;
  912.             tmp2 = 1000;
  913.         } else {
  914.             tmp1 = 1000*leftx/(maxln-wwork/gl_wchar);
  915.             tmp2 = 1000*(wwork/gl_wchar)/maxln;
  916.         }
  917.     } else {            /* do the vertical move */
  918.         flag1 = WF_VSLIDE;
  919.         flag2 = WF_VSLSIZE;
  920.         if (nrow <= hwork/gl_hchar)    {
  921.             tmp1 = 1000;
  922.             tmp2 = 1000;
  923.         } else {
  924.             tmp1 = 1000*toptx/(nrow-hwork/gl_hchar);
  925.             tmp2 = 1000*(hwork/gl_hchar)/nrow;
  926.         }
  927.     }
  928.     wind_get(wh, flag1, &cslide, &nslide, &nslide, &nslide);
  929.     if ((nslide=tmp1) != cslide)    {
  930.         wind_set(wh, flag1, nslide, 0, 0, 0);
  931.     }
  932.     if (resiz)    {
  933.         wind_get(wh, flag2, &cslide, &nslide, &nslide, &nslide);
  934.         if ((nslide=tmp2) != cslide)    {
  935.             wind_set(wh, flag2, nslide, 0, 0, 0);
  936.         }
  937.     }
  938. }
  939.  
  940.  
  941. /* set clip to specified rectangle */
  942. setclip(p)    
  943. GRECT *p;
  944.  
  945. {
  946.     int ptr[4];
  947.  
  948.     grect_conv(p, ptr);
  949.     vs_clip(handle, 1, ptr);
  950. }
  951.  
  952. clrbox(r)
  953. GRECT *r;
  954.  
  955. {
  956.     int p[4];
  957.  
  958.     hide_mouse();
  959.     grect_conv(r, &p);
  960.     vsf_interior(handle, 1);
  961.     vsf_color(handle, 0);
  962.     v_bar(handle, &p);
  963.     show_mouse();
  964. }
  965.  
  966. grect_conv(r, ar)
  967. GRECT *r;
  968. int *ar;
  969. {
  970.     *ar++ = r->g_x;
  971.     *ar++ = r->g_y;
  972.     *ar++ = r->g_x + r->g_w - 1;
  973.     *ar   = r->g_y + r->g_h - 1;
  974. }
  975.  
  976.  
  977. binary(buf)
  978. char *buf;
  979. {
  980.     int i;
  981.     if (!fsiz)    return 0;    /* if file size is 0, return 0 */
  982.     for (i=0; i < 150; i++)    {
  983.         if (*buf++ == 0x0D)    {    /* it is a carriage return */
  984.             if (*buf++ == 0x0A)    { /* it is line feed */
  985.                 return 0;/* it is not a binary file for have carriage return */
  986.             }
  987.         }
  988.     } 
  989.     return 1;            /* it is a binary file */
  990. }
  991.  
  992.  
  993. long findrow(buf, size)
  994. char *buf;
  995. long size;
  996. {
  997.     long n=0;
  998.  
  999.     while (size > 0)    {
  1000.         while (*buf != 0x0D)    {
  1001.             buf++;
  1002.             size--;
  1003.             if (!size)    {
  1004.                 n++;
  1005.                 return (n);
  1006.             }
  1007.         }
  1008.         n++;
  1009.         buf += 2;
  1010.         size -= 2;
  1011.     }
  1012.     return (n);
  1013. }
  1014.  
  1015. bin2str(list, sbuf, dbuf)
  1016. long *list;
  1017. char *sbuf;
  1018. char *dbuf;
  1019. {
  1020.  
  1021.     long *tmp;
  1022.     char *sptr, *dptr, *ptr;
  1023.     int i;
  1024.     long count;
  1025.     char bit, hbit, lbit;
  1026.  
  1027.  
  1028.     if (!fsiz)     /* if the file size is 0, return 0 */
  1029.         return count;
  1030.     sptr = sbuf;
  1031.     dptr = dbuf;
  1032.     count = fsiz;
  1033.     maxln = 67;
  1034.     tmp = list;
  1035.     *tmp++ = dbuf;
  1036.     while (fsiz > 0L)    {
  1037.         ptr = sptr;
  1038.         *dptr++ = 0x20;
  1039.         for (i=0; i < 8; i++)    {
  1040.             /* conver it to hex */
  1041.             bit = *sptr++;
  1042.             if (fsiz-- < 1L)    {
  1043.                 bit = 0x00;
  1044.             }
  1045.             lbit = bit & 0x000F;
  1046.             hbit = (bit>>4) & 0x000F;
  1047.             *dptr++ = myitoa(hbit);
  1048.             *dptr++ = myitoa(lbit);
  1049.             bit = *sptr++;
  1050.             if (fsiz-- < 1L)    {
  1051.                 bit = 0x00;
  1052.             }
  1053.             lbit = bit & 0x000F;
  1054.             hbit = (bit>>4) & 0x000F;
  1055.             *dptr++ = myitoa(hbit);
  1056.             *dptr++ = myitoa(lbit);
  1057.             if (i == 3)    {
  1058.                 *dptr++ = 0x20;
  1059.             }
  1060.             *dptr++ = 0x20;
  1061.         }
  1062.         /* conver it to the printable in the right side */
  1063.         *dptr++ = 0x20;        /* space */
  1064.         *dptr++ = 0x20;    
  1065.         *dptr++ = 0x20;    
  1066.         *dptr++ = 0x20;    
  1067.         *dptr++ = 0x7C;        /* vertical bar */
  1068.         *dptr++ = 0x20;    
  1069.         for (i=0; i < 16; i++)    {
  1070.             bit = *ptr++;
  1071.             if (count-- < 1)    {
  1072.                 bit = 0x00;
  1073.             }
  1074.             if ((bit >= 0x00) && (bit < 0x20))    {
  1075.                 /* for non printable character, print it as a period */
  1076.                 *dptr++ = 0x2E;        
  1077.             } else {
  1078.                 *dptr++ = bit; /* print whatever they are */
  1079.             }
  1080.         }
  1081.         *dptr++ = 0x20;
  1082.         *dptr++ = 0x7C;
  1083.         *dptr++ = 0x00;
  1084.         *tmp++ = dptr;
  1085.     }
  1086.     return OK;
  1087. }
  1088.  
  1089. myitoa(bit)
  1090. char bit;
  1091.  
  1092. {
  1093.  
  1094.     char i;
  1095.  
  1096.     switch(bit)    {
  1097.         case 0x00:
  1098.             i = 0x30;
  1099.             break;
  1100.         case 0x01:
  1101.             i = 0x31;
  1102.             break;
  1103.         case 0x02:
  1104.             i = 0x32;
  1105.             break;
  1106.         case 0x03:
  1107.             i = 0x33;
  1108.             break;
  1109.         case 0x04:
  1110.             i = 0x34;
  1111.             break;
  1112.         case 0x05:
  1113.             i = 0x35;
  1114.             break;
  1115.         case 0x06:
  1116.             i = 0x36;
  1117.             break;
  1118.         case 0x07:
  1119.             i = 0x37;
  1120.             break;
  1121.         case 0x08:
  1122.             i = 0x38;
  1123.             break;
  1124.         case 0x09:
  1125.             i = 0x39;
  1126.             break;
  1127.         case 0x0A:
  1128.             i = 0x41;
  1129.             break;
  1130.         case 0x0B:
  1131.             i = 0x42;
  1132.             break;
  1133.         case 0x0C:
  1134.             i = 0x43;
  1135.             break;
  1136.         case 0x0D:
  1137.             i = 0x44;
  1138.             break;
  1139.         case 0x0E:
  1140.             i = 0x45;
  1141.             break;
  1142.         case 0x0F:
  1143.             i = 0x46;
  1144.             break;
  1145.  
  1146.         defual:
  1147.             break;
  1148.     }
  1149.     return i;
  1150. }
  1151.  
  1152.  
  1153. long gdbufsiz(sbuf, size)
  1154. char *sbuf;
  1155. long size;
  1156. {
  1157.  
  1158.     long count=0;
  1159.     char *sptr;
  1160.     int i=0, j=0;
  1161.  
  1162.  
  1163.     sptr = sbuf;
  1164.     if (*sptr == 0x0D)    { /* the first line is the blank line */
  1165.         count++;
  1166.         count++;
  1167.         sptr += 2;
  1168.         size -= 2;
  1169.     } 
  1170.     while (size > 0)    {
  1171.         count++;     /* a space for the beginning of the line */
  1172.         while ((*sptr != 0x09) && (*sptr != 0x0D))    {
  1173.             i++;
  1174.             sptr++;
  1175.             size--;
  1176.             count++;
  1177.             if (!size)    {    /* end of file */
  1178.                 return count;
  1179.             }
  1180.         }
  1181.         switch(*sptr)    {
  1182.             case 0x09:        /* it is a tab char */
  1183.                 sptr++;
  1184.                 size--;
  1185.                 j = 4 - i%4;    /* calculate how many space should be */
  1186.                 i += j;
  1187.                 switch(j)    {
  1188.                     case 4:            /* four spaces for the tab */
  1189.                         count += 4;
  1190.                         break;
  1191.                     case 3:            /* three spaces for the tab */
  1192.  
  1193.                         count += 3;
  1194.                         break;
  1195.                     case 2:
  1196.                         count += 2;
  1197.                         break;
  1198.                     case 1:
  1199.                         count++;
  1200.                         break;
  1201.                     default:
  1202.                         break;
  1203.                 }
  1204.                 break;
  1205.             case 0x0D:        /* it is a carriage return char */
  1206.                 sptr++;
  1207.                 size--;
  1208.                 count++;
  1209.                 sptr++;
  1210.                 size--;
  1211.                 break;
  1212.             default:
  1213.                 break;
  1214.         }
  1215.         i = 0;
  1216.     }
  1217.     return count;
  1218. }
  1219.  
  1220.  
  1221. asci2str(list, sbuf, dbuf, size)
  1222. long *list;
  1223. char *sbuf;
  1224. char *dbuf;
  1225. long size;
  1226. {
  1227.  
  1228.     long *tmp;
  1229.     char *sptr, *dptr;
  1230.     int i=0, j=0;
  1231.     int width=0;
  1232.  
  1233.  
  1234.     maxln = 0;
  1235.     if (!fsiz) return OK;
  1236.     tmp = list;
  1237.     *tmp++ = dbuf;
  1238.     sptr = sbuf;
  1239.     dptr = dbuf;
  1240.     if (*sptr == 0x0D)    { /* the first line is the blank line */
  1241.         *dptr++ = 0x20;
  1242.         *dptr++ = 0x00;
  1243.         sptr += 2;
  1244.         *tmp++ = dptr;
  1245.         size -= 2;
  1246.     } 
  1247.     while (size > 0)    {
  1248.         *dptr++ = 0x20;            /* a space for the beginning of the line */
  1249.         i++;
  1250.         while ((*sptr != 0x09) && ((*dptr++ = *sptr) != 0x0D))    {
  1251.             i++;
  1252.             sptr++;
  1253.             size--;
  1254.             if (!size)    {    /* end of file */
  1255.                 *dptr = 0x00;
  1256.                 *tmp++ = dptr;
  1257.                 return OK;
  1258.             }
  1259.         }
  1260.         switch(*sptr)    {
  1261.             case 0x09:        /* it is a tab char */
  1262.                 sptr++;
  1263.                 size--;
  1264.                 j = 4 - i%4;    /* calculate how many space should be */
  1265.                 i += j;
  1266.                 switch(j)    {
  1267.                     case 4:            /* four spaces for the tab */
  1268.                         *dptr++ = 0x20;
  1269.                         *dptr++ = 0x20;
  1270.                         *dptr++ = 0x20;
  1271.                         *dptr++ = 0x20;
  1272.                         break;
  1273.                     case 3:            /* three spaces for the tab */
  1274.                         *dptr++ = 0x20;
  1275.                         *dptr++ = 0x20;
  1276.                         *dptr++ = 0x20;
  1277.                         break;
  1278.                     case 2:
  1279.                         *dptr++ = 0x20;
  1280.                         *dptr++ = 0x20;
  1281.                         break;
  1282.                     case 1:
  1283.                         *dptr++ = 0x20;
  1284.                         break;
  1285.                     default:
  1286.                         break;
  1287.                 }
  1288.                 width += i;    /* the width the line */
  1289.                 break;
  1290.             case 0x0D:        /* it is a carriage return char */
  1291.                 sptr++;
  1292.                 size--;
  1293.                 if (*(sptr-2) == 0x0A) {/* it is a blank line */
  1294.                     *(dptr-1) = 0x20;
  1295.                     *dptr++ = 0x00;
  1296.                 } else {
  1297.                     *(dptr-1) = 0x00;
  1298.                 }
  1299.                 *tmp++ = dptr;
  1300.                 sptr++;
  1301.                 size--;
  1302.                 width += i;
  1303.                 maxln = MAX(maxln, width);
  1304.                 width = 0;
  1305.                 break;
  1306.             default:
  1307.                 break;
  1308.         }
  1309.         i = 0;
  1310.     }
  1311.     maxln += 1;        /* for the space of each begining line */
  1312. }
  1313.  
  1314. /*
  1315.  * Get a single event, process it, and return.
  1316.  *
  1317.  */
  1318. domulti(){
  1319.  
  1320.     int event, rut;
  1321.     int skip = 0;
  1322.     long tmp;
  1323.     GRECT box;
  1324.     int prvw, prvh;
  1325.  
  1326.     box.g_x = xwork;
  1327.     box.g_y = ywork;
  1328.     box.g_h = hwork;
  1329.     box.g_w = wwork;
  1330.     
  1331.     event = evnt_multi(MU_MESAG|MU_KEYBD, 1,1,butdown, 0,0,0,0,0, 0,0,0,0,0,
  1332.                         msg,0,0,&mx,&my,&ret,&ret,&keycode,&ret);
  1333.  
  1334.     if (event & MU_KEYBD)    {    /* keyboard was hit */
  1335.         switch(keycode)        {
  1336.             case 0x6200:    {    /* help key */
  1337.                     /* 0: show the new file in the old window */
  1338.                 selagn:
  1339.                     if (select(skip) == EXIT)    {
  1340.                         running = 0;
  1341.                     } else {
  1342.                         /*
  1343.                         Mfree(dbuff);
  1344.                         Mfree(list);
  1345.                         */
  1346.                         openyes = 1;
  1347.                         if ((rut=doopenwd(0, argv[fno])) == OK)    {
  1348.                             skip = 1;
  1349.                             goto selagn;
  1350.                         } else if (rut == ERROR)    {            /* get out */
  1351.                             running = 0;
  1352.                         } /* keep go on */
  1353.                     }
  1354.                 }
  1355.                 break;
  1356.  
  1357.             case 0x4D00: msg[4] = 7;
  1358.                          goto tort;        /* right-arrow key */
  1359.  
  1360.             case 0x4B00: msg[4] = 6;
  1361.                          goto tolf;        /* left-arrow key */
  1362.  
  1363.             case 0x4800: msg[4] = 2;
  1364.                          goto toup;        /* up-arrow key */
  1365.  
  1366.             case 0x5000: msg[4] = 3;
  1367.                          goto todn;        /* down-arrow key */
  1368.  
  1369.             defualt: break;
  1370.         } 
  1371.     } else  if (event & MU_MESAG) {
  1372.         wind_update(TRUE);
  1373.     switch (msg[0]) {
  1374.         case  WM_REDRAW:        /* do the redraw by call redraw routine */
  1375.             if (!openyes)    {
  1376.                 box.g_x = msg[4];
  1377.                 box.g_y = msg[5];
  1378.                 box.g_w = msg[6];
  1379.                 box.g_h = msg[7];
  1380.             } else {
  1381.                 openyes = 0;
  1382.             }
  1383.             /*
  1384.             printf("%d %d %d %d\n", box.g_x, box.g_y, box.g_w, box.g_h);
  1385.             */
  1386.             Redraw(msg[3], &box);
  1387.             break;
  1388.  
  1389.         case  WM_TOPPED:        /* if topped, send to top */
  1390.             wind_set(msg[3], WF_TOP, 0, 0, 0, 0);
  1391.             wind_get(msg[3], WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork);
  1392.             break;
  1393.  
  1394.         case  WM_SIZED:            /* if sized, check for min size, then resize */
  1395.             msg[6] = MAX(msg[6], gl_wchar*8);
  1396.             msg[7] = MAX(msg[7], gl_hchar*4);
  1397.             wind_set(msg[3], WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]);
  1398.             wind_get(msg[3], WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork);
  1399.             if (maxln <= wwork/gl_wchar)    {
  1400.                 leftx = 0;
  1401.             }
  1402.             if (nrow <= hwork/gl_hchar)    {
  1403.                 toptx = 0;
  1404.             }
  1405.             mvslide(msg[3], 3, 1);    
  1406.             mvslide(msg[3], 4, 1);
  1407.             break;
  1408.  
  1409.         case  WM_MOVED:            /* if moved, make sure the window stays on the
  1410.                                    desktop */
  1411.             wind_set(msg[3], WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]);
  1412.             wind_get(msg[3], WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork);
  1413.             break;
  1414.  
  1415.         case  WM_FULLED:        /* if fulled, do toggle routine */
  1416.             toggle(msg[3]);
  1417.             break;
  1418.  
  1419.         case  WM_CLOSED:        /* if closed, set flag */
  1420.             wind_close(msg[3]);
  1421.             running = 0;
  1422.             break;
  1423.  
  1424.         case  WM_VSLID:            /* slide bar was dragged */
  1425.             if (nrow < hwork/gl_hchar)    {
  1426.                 break;
  1427.             }
  1428.             tmp = msg[4] * (nrow-hwork/gl_hchar) / 1000;    /* calc toptx */
  1429.             if (toptx == tmp)    {    /* don't move */
  1430.                 break;
  1431.             }
  1432.             toptx = tmp;
  1433.             Redraw(msg[3], &box);    
  1434.             mvslide(msg[3], 0, 0);
  1435.             break;
  1436.  
  1437.         case  WM_HSLID:            /* slide bar was dragged */
  1438.             if (wwork <= maxln*gl_wchar)        {
  1439.                 tmp = msg[4] * (maxln-wwork/gl_wchar) / 1000; 
  1440.                 if (leftx == tmp)    { /* don't move */
  1441.                     break;
  1442.                 }
  1443.                 leftx = tmp;
  1444.                 Redraw(msg[3], &box);
  1445.                 mvslide(msg[3], 4, 0);
  1446.             }
  1447.             break;
  1448.  
  1449.         case  WM_ARROWED:
  1450.             switch (msg[4])    {
  1451.                 case 0:    /* page up */
  1452.                     if (toptx)    {
  1453.                         tmp = MAX(0, toptx-hwork/gl_hchar);
  1454.                         if (toptx == tmp)    { /* don't move */
  1455.                             break;
  1456.                         }
  1457.                         toptx = tmp;
  1458.                         Redraw(msg[3], &box);     
  1459.                         mvslide(msg[3], msg[4], 0);
  1460.                     }
  1461.                     break;
  1462.  
  1463.                 case 1:    /* page down */
  1464.                      tmp = MIN(nrow-hwork/gl_hchar, 
  1465.                                             toptx+hwork/gl_hchar);
  1466.                     if (toptx == tmp)    {
  1467.                         break;
  1468.                     } else if (nrow < hwork/gl_hchar)    {
  1469.                         ;
  1470.                     } else if (tmp < nrow)    {
  1471.                         toptx = tmp;
  1472.                         Redraw(msg[3], &box);
  1473.                         mvslide(msg[3], msg[4], 0);
  1474.                     } 
  1475.                     break;
  1476.  
  1477.                 case 2:    /* row up */
  1478.                 toup:
  1479.                     if (toptx)    {
  1480.                         toptx = MAX(0, toptx-1);
  1481.                         blit2up(msg[3], &box);
  1482.                         mvslide(msg[3], msg[4], 0);
  1483.                     }
  1484.                     break;
  1485.  
  1486.                 case 3:    /* row down */
  1487.                 todn:
  1488.                     if ((nrow-toptx) > hwork/gl_hchar)    {
  1489.                         toptx = MIN(nrow-hwork/gl_hchar, toptx+1);
  1490.                         blit2dn(msg[3], &box);
  1491.                         mvslide(msg[3], msg[4], 0);
  1492.                     }
  1493.                     break;
  1494.  
  1495.                 case 4:    /* page left */
  1496.                     if (wwork <= maxln*gl_wchar)        {
  1497.                         tmp = MAX(0, leftx-wwork/gl_wchar);
  1498.                         if (leftx == tmp)    {    /* don't move */
  1499.                             break;
  1500.                         }
  1501.                         leftx = tmp;
  1502.                         Redraw(msg[3], &box);
  1503.                         mvslide(msg[3], msg[4], 0);
  1504.                     }
  1505.                     break;
  1506.  
  1507.                 case 5:    /* page right */
  1508.                     if (wwork <= maxln*gl_wchar)        {
  1509.                          tmp = MIN(maxln-wwork/gl_wchar, 
  1510.                                             leftx+wwork/gl_wchar);
  1511.                         if (leftx == tmp)    {    /* don't move */
  1512.                             break;
  1513.                         }
  1514.                         leftx = tmp;
  1515.                         Redraw(msg[3], &box);     
  1516.                         mvslide(msg[3], msg[4], 0);
  1517.                     }
  1518.                     break;
  1519.  
  1520.                 case 6:    /* column left */
  1521.                 tolf:
  1522.                     if (leftx)    {
  1523.                         leftx = MAX(0, leftx-1);
  1524.                         blit2lf(msg[3], &box);
  1525.                         mvslide(msg[3], msg[4], 0);
  1526.                     }
  1527.                     break;
  1528.  
  1529.                 case 7:    /* column right */
  1530.                 tort:
  1531.                     if ((maxln-leftx)*gl_wchar > wwork)        {
  1532.                         leftx = MIN(gl_wchar+maxln-wwork/gl_wchar, leftx+1);
  1533.                         blit2rt(msg[3], &box);
  1534.                         mvslide(msg[3], msg[4], 0);
  1535.                     }
  1536.                     break;
  1537.  
  1538.                 default:
  1539.                     break;
  1540.             }
  1541.             break;
  1542.  
  1543.         case WM_NEWTOP:
  1544.             wind_set(wi_handle, WF_TOP, 0, 0, 0, 0);
  1545.             break;
  1546.  
  1547.  
  1548.         default:
  1549.         break;
  1550.     }
  1551.     wind_update(FALSE);
  1552.     }
  1553. }
  1554.  
  1555.  
  1556. /*
  1557.  * Open virtual workstation.
  1558.  *
  1559.  */
  1560. open_vwork()
  1561. {
  1562.     int i;
  1563.  
  1564.     for (i = 0; i < 10;)    {
  1565.         work_in[i++] = 1;
  1566.     }
  1567.     work_in[10] = 2;
  1568.     handle = phys_handle;
  1569.     v_opnvwk(work_in, &handle, work_out);
  1570.     return(handle);
  1571. }
  1572.  
  1573.  
  1574.  
  1575. /*
  1576.  * Hide the mouse.
  1577.  *
  1578.  */
  1579. hide_mouse()
  1580. {
  1581.     if (!hidden) {
  1582.     graf_mouse(M_OFF, 0L);
  1583.     hidden = TRUE;
  1584.     }
  1585. }
  1586.  
  1587.  
  1588. /*
  1589.  * Show the mouse.
  1590.  *
  1591.  */
  1592. show_mouse() 
  1593. {
  1594.     if (hidden) {
  1595.     graf_mouse(M_ON, 0L);
  1596.     hidden = FALSE;
  1597.     }
  1598. }
  1599.  
  1600.  
  1601. /*
  1602.  *  Display a dialogue box on the screen.
  1603.  *    Input:
  1604.  *        tree - object tree for dialogue box to be displayed.
  1605.  *    Output:
  1606.  *        formw, formh, sx, sy, lx, ly - dimensions of box.
  1607.  */
  1608. dsplymsg(tree)
  1609. OBJECT *tree;
  1610. {
  1611.     form_center(tree,&lx, &ly, &formw, &formh);
  1612.  
  1613.     form_dial(1, 0, 0, 0, 0, lx, ly, formw, formh);
  1614.     objc_draw(tree, 0, 3, lx, ly, formw, formh);
  1615. }
  1616.  
  1617.  
  1618. /*
  1619.  *  Erase a dialogue box from the screen.
  1620.  *    Input:
  1621.  *        formw, formh, sx, sy, lx, ly - dimensions of box.
  1622.  */
  1623. erasemsg()
  1624. {
  1625.     form_dial(3, 0, 0, 0, 0, lx, ly, formw, formh);
  1626. }
  1627.  
  1628.  
  1629.  
  1630. /*
  1631.  * getargs: interpret either MWC args or command-line args (if no MWC).
  1632.  *
  1633.  * USAGE:
  1634.  *    main(argc,argv)
  1635.  *    int argc;
  1636.  *    char *argv[];
  1637.  *    {
  1638.  *        getargs(&argc,&argv);
  1639.  *        ... now process the args and run the program ...
  1640.  *    }
  1641.  *
  1642.  * Allows a max of NARGV arguments: normally 128 is sufficient.
  1643.  *
  1644.  * Call with *(&argc) != 0 if somebody has already parsed the command-
  1645.  * line arguments for you; in that case, if there aren't any
  1646.  * args in the environment, this procedure just returns
  1647.  * because the previous parser has already done its best. 
  1648.  *
  1649.  * Requires getenv().
  1650.  *
  1651.  * Clobbers the environment so children started from here will not
  1652.  * see ARGV= in their env (unless it's put there later).  This also
  1653.  * means you can't call getargs twice...
  1654.  *
  1655.  * Interprets the environment string like MWC does.
  1656.  *
  1657.  * Does not validate the ARGV string.  This is a bug.  The convention
  1658.  * which has developed means that all programs which launch children
  1659.  * must use the ARGV convention, or none may, because if one which does
  1660.  * use it launches one which doesn't, which launches one which does,
  1661.  * then the last one will see the middle one's ARGV.
  1662.  */
  1663.  
  1664.  
  1665. getargs(p_argc,p_argv)
  1666. int *p_argc;
  1667. char ***p_argv;
  1668. {
  1669.     extern char *_base;
  1670.     char *getenv();
  1671.     register char *eptr;
  1672.     register int count = 0;
  1673.     char hold;
  1674.  
  1675.     if (eptr = getenv("ARGV")) {
  1676.     eptr += strlen(eptr) + 1;
  1677.     while (count < NARGV-1 && *eptr) {
  1678.         argv[count++] = eptr;
  1679.         eptr += strlen(eptr) + 1;
  1680.     }
  1681.  
  1682.     /* clobber "ARGV=" so environment ends there,    */
  1683.     /* so children won't see these args in the env.    */
  1684.  
  1685.     eptr = getenv("ARGV");
  1686.     while (*(--eptr) != 'A') ;
  1687.     *eptr = 0;
  1688.     }
  1689.     else {
  1690.     /* if we've already got args, don't do anything! */
  1691.         if (*p_argc != 0) return *p_argc;
  1692.     count = *(_base+0x80);
  1693.     *(_base+0x81+count) = 0;
  1694.     strcpy(argcopy,_base+0x81);
  1695.     eptr = argcopy;
  1696.     argv[0] = "runtime";
  1697.     count = 1;
  1698.     while (1) {
  1699.         while (*eptr == ' ') eptr++;    /* skip leading spaces */
  1700.         if (!*eptr) break;            /* if end, quit */
  1701.         argv[count++] = eptr;        /* not end: next arg */
  1702.         while (*eptr && *eptr != ' ') eptr++;   /* skip nonwhite */
  1703.         hold = *eptr;            /* save old value */
  1704.         *eptr = 0;                /* null terminate */
  1705.         if (!hold) break;            /* if old was null, end */
  1706.         else eptr++;            /* else increment & loop */
  1707.     }
  1708.     }
  1709.     argv[count] = eptr;
  1710.     *p_argv = &argv[0];
  1711.     *p_argc = count;
  1712.     return count;
  1713. }
  1714.  
  1715.  
  1716. /*
  1717.  * getenv: get the value of an environment string parameter
  1718.  */
  1719.  
  1720. char *getenv(s)
  1721. char *s;
  1722. {
  1723.     extern long *_base;        /* set by gemstart */
  1724.     char *p;
  1725.     char *start;
  1726.     int temp;
  1727.  
  1728.     p = _base[11];
  1729.     while (*p) {
  1730.     for (start=p ; *p && *p != '='; p++);
  1731.     if (*p) {
  1732.         *p = '\0';
  1733.         temp = strcmp(start,s);
  1734.         *p = '=';
  1735.         if (temp == 0) {
  1736.         return ++p;
  1737.         }
  1738.         while (*p) p++;    /* no match; skip to next */
  1739.     }
  1740.     p++;
  1741.     }
  1742.     return 0L;
  1743. }
  1744.  
  1745.  
  1746. /*
  1747.  * Select the file that will be show.
  1748.  */
  1749.  
  1750. select(skip)
  1751. int skip;
  1752.  
  1753. {
  1754.  
  1755.  
  1756.     wind_update(BEG_UPDATE);     /* lock screen */
  1757.     for (;;)
  1758.     {
  1759.     switch (doscrbar(skip))
  1760.         {
  1761.             case OKDO:  wind_update(END_UPDATE);    /* unlock screen */
  1762.                         return OK;
  1763.             case EXIT:  erasemsg();        /* erase the select dialog box */
  1764.                         wind_update(END_UPDATE);    /* unlock screen */
  1765.                         return EXIT;
  1766.             default:    break;
  1767.         }
  1768.     }
  1769. }
  1770.  
  1771.  
  1772. doscrbar(skip)
  1773. int skip;
  1774.  
  1775. {
  1776.  
  1777.     int but;
  1778.     int xrun = 1;
  1779.     long mystrcp();
  1780.  
  1781.     showasc = 1;    /* default for showing the binary file */
  1782.  
  1783.     scrpnl[OKDO].ob_state = NORMAL;
  1784.     
  1785.     if (!skip)    {
  1786.         showstd = 0;
  1787.         /* set form for first display */
  1788.            totalpart(tolfile, tolstr);
  1789.         scrpnl[TOLFILE].ob_spec = tolstr;
  1790.         scrpnl[TOLFILE].ob_state = NORMAL;
  1791.  
  1792.         scrpnl[FILESTR].ob_spec = mystrcp(ckupper(argv[fno]));
  1793.         scrpnl[FILESTR].ob_state = NORMAL;
  1794.  
  1795.         scrpnl[SCRUP].ob_state = NORMAL;
  1796.         scrpnl[SCRDN].ob_state = NORMAL;
  1797.         scrpnl[SCRLF].ob_state = NORMAL;
  1798.         scrpnl[SCRRT].ob_state = NORMAL;
  1799.  
  1800.         if (showlen <= 21)  {/* the show box only show 21 char */
  1801.             scrpnl[SCRLF].ob_state = DISABLED;
  1802.             scrpnl[SCRRT].ob_state = DISABLED;
  1803.         }
  1804.         scrpnl[EXIT].ob_state = NORMAL;
  1805.  
  1806.         ARROW_MOUSE;
  1807.         dsplymsg(scrpnl);
  1808.     } else {
  1809.         objc_draw(scrpnl, OKDO, 3, lx, ly, formw, formh);
  1810.     }
  1811.  
  1812.     /*
  1813.      * Edit the thing;
  1814.      * canonical event-driven switch().
  1815.      */
  1816.     while (xrun)     {
  1817.         switch ((but = form_do(scrpnl, -1)))
  1818.             {
  1819.                 case EXIT:    xrun = 0;            /* return */
  1820.                             break;
  1821.                 case OKDO:  if (isdir(argv[fno]))    {  /* it is a dir */
  1822.                                 /* can't show the directory */
  1823.                                 form_alert(1, cnsdir);
  1824.                                 scrpnl[OKDO].ob_state = NORMAL;
  1825.                                 objc_draw(scrpnl, OKDO, 3, lx,ly, formw,formh);
  1826.                             } else {
  1827.                                 xrun = 0;
  1828.                             }
  1829.                             break;
  1830.                 case SCRUP:    sepadj(-1, scrpnl);    break;
  1831.                 case SCRDN:    sepadj(1, scrpnl);    break;
  1832.                 case SCRLF:    sepsft(-1, scrpnl);    break;
  1833.                 case SCRRT:    sepsft(1, scrpnl);    break;
  1834.                 default:    break;
  1835.               }
  1836.       }
  1837.     if (scrpnl[BINARYB].ob_state & SELECTED)    {
  1838.         showasc = 0;
  1839.     }
  1840.     return but;
  1841. }
  1842.  
  1843.  
  1844. long mystrcp(str)
  1845. char *str;
  1846. {
  1847.  
  1848.     int i;
  1849.  
  1850.     if ((showlen=strlen(str)) <= 21)    {
  1851.         i=showlen-showstd;
  1852.         strcpy(&showfn[1], str);
  1853.     } else {
  1854.         if ((i=showlen-showstd) >= 21)    {
  1855.             strncpy(&showfn[1], str+showstd, 21);
  1856.         } else {
  1857.             strcpy(&showfn[1], str+showstd);
  1858.         }
  1859.     }
  1860.     if (showstd)    {
  1861.         showfn[0] = 0xAE;
  1862.     } else     {
  1863.         showfn[0] = 0x20;
  1864.     } 
  1865.     if (i > 21)    {
  1866.         showfn[22] = 0xAF;
  1867.     } else {
  1868.         showfn[22] = 0x20;
  1869.         if (showlen < 21)    {
  1870.             showfn[showlen+1] = 0x20;
  1871.             showfn[showlen+2] = 0;
  1872.         }
  1873.     }
  1874.     showfn[23] = 0;
  1875.     return(&showfn[0]);
  1876. }
  1877.  
  1878.  
  1879.  
  1880.  
  1881. sepsft(sftdir, pnl)
  1882. int sftdir;
  1883. OBJECT *pnl;
  1884. {
  1885.     long mystrcp();
  1886.  
  1887.     if (sftdir > 0)    {
  1888.         if (showlen-showstd > 21)    {
  1889.             showstd++;
  1890.             pnl[FILESTR].ob_spec = mystrcp(argv[fno]);
  1891.             pnl[FILESTR].ob_state = NORMAL;
  1892.             objc_draw(pnl, FILESTR, 3, lx, ly, formw, formh);
  1893.         }
  1894.     } else {
  1895.         if (showstd)    {
  1896.             showstd--;
  1897.             pnl[FILESTR].ob_spec = mystrcp(argv[fno]);
  1898.             pnl[FILESTR].ob_state = NORMAL;
  1899.             objc_draw(pnl, FILESTR, 3, lx, ly, formw, formh);
  1900.         }
  1901.     }
  1902. }
  1903.  
  1904. /*
  1905.  * Adjust partition `pno' size by `amt';
  1906.  * if `pno' is -1, just recompute and update disk space left indicator.
  1907.  *
  1908.  * A partition of size zero is disabled.
  1909.  */
  1910.  
  1911.  
  1912.  
  1913. sepadj(amt, pnl)
  1914. int amt;
  1915. OBJECT *pnl;
  1916.  
  1917. {
  1918.         long mystrcp();
  1919.  
  1920.         if (amt > 0)    {
  1921.             if (fno+1 > tolfile)    {
  1922.                 return OK;
  1923.             } else    {
  1924.                 fno++;
  1925.                 showstd = 0;
  1926.             }
  1927.         } else {
  1928.             if (fno-1 < 1)    {
  1929.                 return OK;
  1930.             } else {
  1931.                 fno--;
  1932.                 showstd = 0;
  1933.             }
  1934.         }
  1935.  
  1936.         pnl[FILESTR].ob_spec = mystrcp(ckupper(argv[fno]));
  1937.         pnl[FILESTR].ob_state = NORMAL;
  1938.         if (showlen <= 21)  {/* the show box only show 21 char */
  1939.             pnl[SCRLF].ob_state = DISABLED;
  1940.             pnl[SCRRT].ob_state = DISABLED;
  1941.         } else {
  1942.             pnl[SCRLF].ob_state = NORMAL;
  1943.             pnl[SCRRT].ob_state = NORMAL;
  1944.         }
  1945.         objc_draw(pnl, SCRLF, 3, lx, ly, formw, formh);
  1946.         objc_draw(pnl, SCRRT, 3, lx, ly, formw, formh);
  1947.         objc_draw(pnl, FILESTR, 3, lx, ly, formw, formh);
  1948.  
  1949.         return OK;
  1950. }
  1951.  
  1952. /*
  1953.  * find out the total partitions
  1954.  */
  1955.  
  1956. totalpart(num, str)
  1957.  
  1958. int num;
  1959. char *str;
  1960.  
  1961. {
  1962.     int  i=0, j=0;
  1963.     char tem[10];
  1964.  
  1965.     /* conver the integer to ASCII */
  1966.     do    {    /* generate digits in reverse order */
  1967.         tem[i++] = num % 10 + '0';    /* get next digits */
  1968.     } while ((num /= 10) > 0);        /* delete it */
  1969.  
  1970.     for (; i > 0; )    { /* reverse string 'str' in place */
  1971.         *str++ = tem[--i];
  1972.         j++;
  1973.     }
  1974.     for (; j < 5; j++)    
  1975.         *str++ = ' ';
  1976.        *str = '\0';
  1977. }
  1978.  
  1979.